package com.tbsoft.ehr.action.attendance;

import java.util.List;

import com.tbsoft.ehr.action.BaseAction;
import com.tbsoft.ehr.model.Department;
import com.tbsoft.ehr.model.ServiceCustomer;
import com.tbsoft.ehr.model.StaffInfo;
import com.tbsoft.ehr.model.YearLeave;
import com.tbsoft.ehr.service.attendance.AttendanceService;
import com.tbsoft.ehr.service.staffile.StaffFileService;

public class YearLeaveAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	//用户id/姓名
	private String staffName;
	//服务客户id
	private String serviceCustomerId;	
	//部门id
	private String deptId;
	
	private List<YearLeave> yearLeaveLst;
	private AttendanceService attendanceService;
	private StaffFileService staffFileService;

	public String getServiceCustomerId() {
		return serviceCustomerId;
	}

	public void setServiceCustomerId(String serviceCustomerId) {
		this.serviceCustomerId = serviceCustomerId;
	}

	public String getDeptId() {
		return deptId;
	}

	public void setDeptId(String deptId) {
		this.deptId = deptId;
	}

	public String getStaffName() {
		return staffName;
	}

	public void setStaffName(String staffName) {
		this.staffName = staffName;
	}

	public List<YearLeave> getYearLeaveLst() {
		return yearLeaveLst;
	}

	public void setYearLeaveLst(List<YearLeave> yearLeaveLst) {
		this.yearLeaveLst = yearLeaveLst;
	}

	public void setAttendanceService(AttendanceService attendanceService) {
		this.attendanceService = attendanceService;
	}
	
	public void setStaffFileService(StaffFileService staffFileService) {
		this.staffFileService = staffFileService;
	}

	public String query() {
		int pageNum = this.getPageNum() > 0 ? this.getPageNum() - 1 : 0;
		int startIndex = pageNum * getNumPerPage();		
		
		Department dept = null;
		ServiceCustomer sc = null;
		if(deptId!=null&&!deptId.isEmpty()) {
			dept = new Department(deptId);
		}
		if(serviceCustomerId!=null&&!serviceCustomerId.isEmpty()){
			sc = new ServiceCustomer(serviceCustomerId);
		}
		StaffInfo si = new StaffInfo();
		si.setDepartment(dept);
		si.setServiceCustomer(sc);
		si.setName(staffName);
		
		int count = this.staffFileService.getStaffFileCount(si,null,null);
		setTotalCount(count);
		setPageNumShown((getNumPerPage()+count)/getNumPerPage());						
			
		yearLeaveLst = attendanceService.queryYearLeaveByCondton(si,startIndex,getNumPerPage());
		return "browse";
	}
}
